import requests


class IHRMEmpApi:
    @classmethod
    def add_emp(cls, token, add_data):
        url = 'http://ihrm2-test.itheima.net/api/sys/user'
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}'
        }

        resp = requests.post(url=url, headers=headers,json=add_data)
        return resp

    @classmethod
    def del_emp(cls, token, emp_id):
        url = 'http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}'
        }
        resp = requests.delete(url=url, headers=headers)
        return resp

    @classmethod
    def update_emp(cls, token, emp_id, update_data):
        url = 'http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}'
        }
        resp = requests.put(url=url, headers=headers, json=update_data)
        return resp

    @classmethod
    def query_emp(cls, token, emp_id):
        url = 'http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}'
        }
        resp = requests.get(url=url, headers=headers)
        return resp

    @classmethod
    def query_emp_list(cls, token, page=1, size=100):
        url = f'http://ihrm2-test.itheima.net/api/sys/user?page={page}&size={size}'
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}'
        }
        resp = requests.get(url=url, headers=headers)
        return resp
